home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / RTX2000.ZIP / rtx2000 / monitor / debugger next >
Text File  |  1992-12-02  |  7KB  |  219 lines

  1. ( ************************** Debugger  ********************************* 
  2.   See main file for description of monitor.
  3.  
  4.   Debugger commands:
  5.      A hex_address                              Alter Memory
  6.      C hex_address_a hex_address_b hex_count    Copy Memory a to Memory b
  7.      D hex_address hex_count                    Dump Memory
  8.      G hex_address                              Go to Address
  9.      S                                          Print stack pointer register
  10.      X                                          Enter Download mode
  11.  
  12.      Download mode accepts a ".ols" file generated by the fc complier when fc
  13.      is invoked with the -o option.  Download mode accepts the ascii/hex file 
  14.      and loads it into memory. Once download mode is entered, the monitor 
  15.      remains in download mode until an escape character is received.  When 
  16.      an escape is received, the monitor will print out a check sum that 
  17.      should be zero after error free download.  
  18.       
  19. )
  20.  
  21. #macro ESC 0x1b
  22. #macro 'A' 0x41
  23. #macro 'C' 0x43
  24. #macro 'D' 0x44
  25. #macro 'G' 0x47
  26. #macro 'S' 0x53
  27. #macro 'X' 0x58
  28. #macro '>' 0x3E
  29. #macro CR 0xD
  30. #macro LF 0xA
  31.  
  32.  
  33. cvariable cmd_index            ( Index of next char in buffer )
  34. cvariable altmode              ( =TRUE for alter memory mode, FALSE otherwise )
  35. variable alt_address          ( Address for alter memory mode )
  36. variable mon_checksum         ( Checksum for download )
  37. cvariable abort_load          ( =TRUE for load abort, FALSE otherwise )
  38. 32 carray cmdbuffer           ( Command buffer )
  39.  
  40.  
  41. : do_prompt ( -- )
  42. ( Print out debugger prompt )
  43.   0 cmd_index c!         ( point to start of command buffer )
  44.   PROMPT emit_string
  45. ;
  46.  
  47. : do_aprompt ( a -- )
  48. ( Prompt for memory alter )
  49.    0 cmd_index c!       ( point to start of command buffer )
  50.    newline              ( carriage return line feed )
  51.    alt_address @ 
  52.    dup .x                 ( Print address )
  53.    @ .x                   ( Print word value )
  54.    '>' emit               ( Print a prompt character )
  55.  
  56. xlink
  57. : debug_init ( -- )
  58. ( Initialize debugger )
  59.    FALSE altmode c!           ( Normal command mode )
  60.    do_prompt
  61. ;
  62.  
  63. xlink
  64. : debugger ( -- )
  65. ( Waits for, then processes character from test port )
  66.    key
  67.    dup emit                    ( echo char )
  68.    toupper                     ( Force to upper case )
  69.    dup 0x8 = if               ( Check for backspace )
  70.      cmd_index c@ dup if      ( Make sure were not already at start of buffer )
  71.        1 -                    ( do backspace by decrementing index )
  72.      then
  73.    else
  74.      cmd_index c@ over over cmdbuffer + c!   ( save char in buffer )
  75.      1 + 31 and                             ( increment index and mask )
  76.    then
  77.    cmd_index c!                           ( save new cmd_index )
  78.    CR = if
  79.       cmdbuffer skip_space       ( Point to first non space char )
  80.       altmode c@ if
  81.            ram_alter           ( alter memory )
  82.        else
  83.            parse_cmd           ( execute command )
  84.        then
  85.    then
  86. ;
  87.  
  88. : parse_cmd  ( a -- )
  89. ( Parse input command at address a )
  90.      c@+ swap                  ( Get first char, char on top, address next )
  91.      dup 'X' = if
  92.        newline
  93.        downloader             ( download software )
  94.        mon_checksum @ .x
  95.      then
  96.      dup 'A' = if
  97.        swap getnum drop alt_address !    ( Alt function address )
  98.        drop
  99.        TRUE altmode c!                ( Set to alter mode )
  100.        do_aprompt
  101.        exit
  102.      then
  103.      dup 'C' = if
  104.         swap getnum getnum     ( get source and destination addresses )
  105.         >r swap r>             ( source second, destination third )
  106.         getnum drop            ( get count )
  107.         cpy_ram_ram            ( Copy RAM to RAM )
  108.        0 swap                  ( leave two parameters on stack, char on top )
  109.      then
  110.      dup 'D' = if
  111.        swap getnum getnum drop  ( get address and count )
  112.        dumper                   ( do dump )
  113.        0 swap                   ( leave two parameters on stack, char on top )
  114.      then
  115.      dup 'S' = if
  116.         newline
  117.         spr@ .x                     ( print stack pointer register )
  118.      then
  119.      dup 'G' = if
  120.        newline
  121.        >r         ( put char on return stack )
  122.        getnum drop execute    ( Go to )
  123.        0
  124.        r>
  125.      then
  126.      drop                                      ( Drop character )
  127.      drop                                      ( Drop address )
  128.      do_prompt               ( write debugger prompt )
  129. ;
  130.  
  131. : directnum  ( -- n )
  132. ( Get a hex number directly from test port stream, ignore command buffer
  133.   Return 0 if abort_load = TRUE )
  134.    0
  135.    4 for                    ( Always 4 hex digits per number for download )
  136.       begin 
  137.          abort_load c@ if
  138.            TRUE               ( No processing for abort, return 0 )
  139.          else
  140.            key                ( Get a char  )
  141.            dup emit            ( Echo it )
  142.            dup CR = if
  143.              LF emit          ( send line feed for CR )
  144.            then
  145.            dup ESC = if
  146.              TRUE abort_load c!   ( abort load )
  147.            then
  148.            do_digit not
  149.          then
  150.       until                 ( Repeat until valid nibble or abort )
  151.    next
  152.    dup mon_checksum @ +       ( add to checksum )
  153.    rotate_right
  154.    mon_checksum !             ( save checksum )
  155. ;
  156.  
  157. : downloader ( -- )
  158. ( download from PC )
  159.    FALSE abort_load c!    ( load mode )
  160.    0 mon_checksum !       ( clear checksum )
  161.    begin
  162.      directnum drop       ( Configuration )
  163.      directnum            ( Start address )
  164.      directnum            ( Length )
  165.      directnum drop       ( header checksum )
  166.      abort_load c@ if
  167.        drop
  168.      else
  169.        for
  170.          directnum
  171.          swap !+         ( store data into memory if load not aborted )
  172.        next
  173.      then
  174.      drop               ( drop address )
  175.      mon_checksum @
  176.      directnum - mon_checksum !    ( Full checksum )
  177.      abort_load c@
  178.    until
  179. ;
  180.  
  181. : dumper  ( s l -- )
  182. ( Dump starting at s, length l words  )
  183.    0                ( dump count for newlines )
  184.    swap
  185.    for 
  186.       dup 7 and 0= if       ( Print out address every 8 words )
  187.          newline
  188.          over .x               ( print address )
  189.          ": " emit_string      ( print colon )
  190.       then
  191.       swap
  192.         @+             ( Get data using dpr )
  193.       swap .x               ( Print data )
  194.       swap 1 +
  195.    next
  196.    drop
  197.    drop
  198. ;
  199.  
  200. : ram_alter ( a -- )
  201. ( Alter RAM memory, a address of text string )
  202.    dup c@ CR = if
  203.        FALSE altmode c!      ( turn off alter mode )
  204.        drop
  205.        do_prompt
  206.    else
  207.        getnum drop
  208.        alt_address @ !+ alt_address !
  209.        do_aprompt
  210.     then
  211. ;
  212.  
  213.  
  214.  
  215.  
  216.      
  217.     
  218.